#include <bits/stdc++.h>

using namespace std;
const int maxn=110;
struct node
{
    int weight;
    vector<int> childs;
}Node[maxn];
bool child_cmp(int a,int b)
{
    return Node[a].weight>Node[b].weight;
}
int node_n,non_leaf,given_s;
int path[maxn];
void DFS(int index,int numNode,int sum)
{
    if (sum>given_s)
    {
        return;
    }
    if (sum==given_s)
    {
        if (Node[index].childs.size()!=0)
        {
            return;
        }
        for (int i=0;i<numNode ;++i )
        {
            printf("%d",Node[path[i]].weight);
            if (i<numNode-1)
            {
                printf(" ");
            }
            else
            {
                printf("\n");
            }
        }
        return;
    }
    for (int i=0;i<Node[index].childs.size() ;++i )
    {
        int child=Node[index].childs[i];
        path[numNode]=child;
        DFS(child,numNode+1,sum+Node[child].weight);
    }
}
int main_1053_1()
{
    scanf("%d%d%d",&node_n,&non_leaf,&given_s);
    for (int i=0;i<node_n ;++i )
    {
        scanf("%d",&Node[i].weight);
    }
    int id,k,child;
    for (int i=0;i<non_leaf ; ++i)
    {
        scanf("%d%d",&id,&k);
        for (int j=0;j<k ;++j )
        {
            scanf("%d",&child);
            Node[id].childs.push_back(child);
        }
        sort(Node[id].childs.begin(),Node[id].childs.end(),child_cmp);
    }
    path[0]=0;
    DFS(0,1,Node[0].weight);
    return 0;
}
